package com.deyinet.bdcms.controller;

import com.deyinet.bdcms.core.vo.Page;
import com.deyinet.bdcms.entity.Syslog;
import com.deyinet.bdcms.entity.Sysuser;
import com.deyinet.bdcms.service.ILogsService;
import com.deyinet.bdcms.service.ISysuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/21 0021.
 */
@Controller
@RequestMapping("/sysmanage/syslogs")
public class syslogsController {

    @Autowired
    private ILogsService logsService;
    @Autowired
    private ISysuserService sysuserService;
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public void list() {
    }

    @RequestMapping(value = "/listdata")
    @ResponseBody
    public Map<String, Object> listdata(HttpServletRequest request,Page page)
            throws Exception {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String username = request.getParameter("username");
        String createdatestart = request.getParameter("createdatestart");
        String createdateend = request.getParameter("createdateend");
        Timestamp ts=null;
      if (createdatestart!=null&&!"".equals(createdatestart)){
             ts=new Timestamp(format1.parse(createdatestart).getTime());//string-->Timestamp
       }
        Timestamp te=null;
        if (createdateend!=null&&!"".equals(createdateend)){
            te=new Timestamp(format1.parse(createdateend).getTime());//string-->Timestamp
        }
        Syslog log=new Syslog();
        Sysuser sysuser=new Sysuser();
        if (username!=null&&!"".equals(username)){
            sysuser.setName(username);
            log.setSysuserByUserid(sysuser);
        }

        logsService.findByExampleLike(log, page, ts, te);
        Map<String, Object> info = new HashMap<>();
        info.put("totalRow", page.getTotalRow());
        info.put("pageCurrent", page.getPageCurrent());
        info.put("list", page.getList());
        return info;
    }
}
